﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Gp.Scripts.Core;
using Sirenix.OdinInspector;

namespace Gp.AI {
    [CreateNodeMenu("一般行为/移动")]
    public class MoveAINode : NormalAINode {
        // [ProgressBar(0, 4)]
        // public int targetPos;
        [Title("偏好位置")]
        [LabelText("1号位")] public bool pos0;
        [LabelText("2号位")] public bool pos1;
        [LabelText("3号位")] public bool pos2;
        [LabelText("4号位")] public bool pos3;

        public override AINodeEntry NodeEntry() {
            return new MoveAINodeEntry(this);
        }


        public IEnumerable<int> TargetPos() {
            if (pos0) yield return 0;
            if (pos1) yield return 1;
            if (pos2) yield return 2;
            if (pos3) yield return 3;
        }
    }


    public class MoveAINodeEntry : NormalAINodeEntry<MoveAINode> {
        public MoveAINodeEntry(MoveAINode data) : base(data) { }

        // private AttachCell _targetPos;
        private MoveSkillEntity _skill;

        protected override void PreCalculate() {
            // _skill = Unit.AbilityManager.MoveSkill;
            //
            // // var current = this.Unit.CurrentCell;
            // var targets = Data.TargetPos();
            //
            // // 如果已经处于偏好位置上
            // var destinations = targets as int[] ?? targets.ToArray();
            // if (destinations.Contains(current.Index)) return;
            //
            // // 选择离当前距离最近的
            // var res = destinations.Min(x => Math.Abs(current.Index - x));
            //
            // _targetPos = CellGridSystem.Instance.PlaceHolder.GetCell(Unit.Side, res);
        }

        // public override IEnumerator OnExecute() {
        //     // yield return _skill.AIExecute(new UnitSelectContext(_targetPos));
        // }


        public override bool ShouldPerform() {
            // return _targetPos != null && _skill.CanMove(_targetPos);
            return false;
        }


        protected override AIActionArgs GetActionInfo() {
            return AIActionArgs.Build(Unit.ComSkill.MoveSkill);
        }
    }
}